package com.woniuxy.myteststroredata;

import java.util.*; /**
 * description: TestStoreData <br>
 * date: 2022/2/4 4:51 下午 <br>
 * author: shesaifei <br>
 * version: 1.0 <br>
 */

/**
 * 测试表格数据的存储
 * ORM思想的简单实验：
 * 每一行数据使用一个：Javabean对象
 * 整个表格使用一个map/list
 */
public class TestStoreData02 {
    public static void main(String[] args) {
        User user1 = new User(1001, "张三", 20000, "2018.5.5");
        User user2 = new User(1002, "李四", 30000, "2005.4.4");
        User user3 = new User(1003, "王五", 3000, "2020.5.4");

        //使用list
        List<User> list = new ArrayList<>();
        list.add(user1);
        list.add(user2);
        list.add(user3);
        for (User user : list) {
            System.out.println(user);
        }


        System.out.println("++++++++");
        //使用map
        Map<Integer, User> map = new HashMap<>();
        map.put(1001, user1);
        map.put(1002, user2);
        map.put(1003, user3);
        Set<Integer> keyset = map.keySet();
        for (Integer key : keyset) {
            System.out.println(key + "==" + map.get(key));
        }
    }
}

//一个完整的javabean。要有set/get方法，以及一个无餐的构造器！
class User {
    private int id;
    private String name;
    private double salary;
    private String hiredate;

    public User() {
    }

    public User(int id, String name, double salary, String hiredate) {
        this.id = id;
        this.name = name;
        this.salary = salary;
        this.hiredate = hiredate;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    public String getHiredate() {
        return hiredate;
    }

    public void setHiredate(String hiredate) {
        this.hiredate = hiredate;
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", salary=" + salary +
                ", hiredate='" + hiredate + '\'' +
                '}';
    }
}